﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaveEngine.Framework;
using WaveEngine.Framework.Graphics; 
#endregion

namespace WaveEngine.Extensions.Behaviors
{
    public class ChildDraworderBehavior : Behavior
    {
        [RequiredComponent]
        private Transform2D transform2D = null;

        private Transform2D parentTransform2D;

        public float DrawOrderOffset { get; set; }

        public ChildDraworderBehavior()
        {
            this.UpdateOrder = 1f;
        }

        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            this.parentTransform2D = this.Owner.Parent.FindComponent<Transform2D>();
        }

        protected override void Update(TimeSpan gameTime)
        {
            var childDrawOrder = this.parentTransform2D.DrawOrder + this.DrawOrderOffset;

            //if (childDrawOrder < 0 || childDrawOrder > 1)
            //{
            //    throw new NotSupportedException();
            //}

            this.transform2D.DrawOrder = childDrawOrder;
        }
    }
}
